from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.conf import settings

from apps.system.models import Upload


# Create your models here.

class Diary(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='作者', on_delete=models.PROTECT)
    content = models.CharField(verbose_name='内容', max_length=500)
    images = models.ManyToManyField(Upload, verbose_name='图片')
    delete = models.BooleanField(verbose_name='删除', default=False)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True, editable=False)
    like_count = models.IntegerField(verbose_name='点赞', default=0)
    collect_count = models.IntegerField(verbose_name='收藏', default=0)
    browse_count = models.IntegerField(verbose_name='浏览量', default=0)

    @staticmethod
    def get_content_type():
        return ContentType.objects.get(model='Diary'.lower())

    class Meta:
        db_table = 'diary'
        verbose_name = '日记'
        default_permissions = ()
